<?php
class Tourism extends BZ_Controller
{
    public function _init()
    {
        $this->load->helper('city');
        $this->load->model('advert_model', 'advert');
        $this->load->model('promotion_project_model', 'promotion_project');
        $this->load->model('tourism_goods_base_model', 'tourism_goods_base');
        $this->load->model('tourism_cart_goods_model', 'tourism_cart_goods');
        $this->load->model('tourism_goods_attr_model', 'tourism_goods_attr');
        $this->load->model('tourism_enshrine_model', 'tourism_enshrine');
        $this->load->model('cms_block_model', 'cms_block');
        $this->load->model('tourism_key_word_model', 'tourism_key_word');
        $this->load->model('tourism_provider_model','tourism_provider');
    }
    
    public function index()
    {
        if (!$this->cache->memcached->get('wapshangpinHomePageCache')) {
            $this->data = array(
                'headTitle'     => $this->data['headTitle'],
                'advert_img'    => $this->advert->findByParams(['status'=> 1, 'opentype' => 'link', 'position' => 13], '*', null, 'sort ASC')->result(), //首页广告
                'sales_rank'    => $this->tourism_goods_base->findBySalesRank(12)->result(), //销量排行
                'local_special' => $this->tourism_goods_base->findLocalSpecial(28)->result(),  //特产推荐
                'provider'      => $this->tourism_provider->findProvider(16,0)->result(),
                'cmsBlocks'     => $this->cms_block->findByBlockIds(array('shangpin_home_leftmenu', 'shangpin_home_hottop')),
            );
            $this->cache->memcached->save('wapshangpinHomePageCache', $this->data, 3 * 24 * 3600);
        } else {
            $this->data = $this->cache->memcached->get('wapshangpinHomePageCache');
        }
        $this->data['uid'] = $this->uid;
        $this->data['keyWordList'] = $this->tourism_key_word->findByParams(['provider_id' => $this->providerUid, 'status' => 1]);
        $this->load->view('tourism/tourism/index', $this->data);
    }

    public function search()
    {
        $this->data['keyWordList'] = $this->tourism_key_word->findByParams(['provider_id' => $this->providerUid, 'status' => 1]);
        $this->load->view('tourism/tourism/search', $this->data);
    }
    
    public function error404()
    {
        $this->load->view('tourism/tourism/404', $this->data);
    }

    public function payFail()
    {
        $this->load->view('tourism/tourism/fail', $this->data);
    }

    public function paySuccess()
    {
        $this->load->view('tourism/tourism/success', $this->data);
    }
    
     /**
     *ajax获取当前地址，并存入cookie --
     */
    public function ajaxCurrentCity()
    {
        $location  = $this->input->get('location');
        $coordtype = $this->input->get('coordtype');
        $output    = $this->input->get('output');
        $pois      = $this->input->get('pois');
        $cityName = locationCurrentCity($location, $coordtype, $output, $pois);
        if ($cityName) {
            set_cookie('city', $cityName['city'], 43250);
            set_cookie('province', $cityName['province'], 43250);
        }
        echo json_encode(array(
            'status'   => true,
            'messages' => $cityName['province'],
        ));exit;
    }
}